//
//  BCMyChargeVC.m
//  BangcaiSale
//
//  Created by lsy on 16/7/7.
//  Copyright © 2016年 Bangcai. All rights reserved.
//

#import "BCMyChargeVC.h"
#import "BCMineChargeWeekCollectionViewCell.h"
#import "BCMineChargeMoneyCollectionViewCell.h"
#import "BCMineChargeInfoCollectionViewCell.h"
#import "BCLogoCollectionViewCell.h"

@interface BCMyChargeVC () <UICollectionViewDelegate,UICollectionViewDataSource>
//主视图
@property (nonatomic, strong) UICollectionView *mainCollectionView;
@end

@implementation BCMyChargeVC

-(void)viewDidLoad {
    [super viewDidLoad];
    [self p_initNavgationBar];
    [self p_initCollectionView];
}

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"isFromMianPage_GotoMyCharge"];
    //隐藏导航栏
    self.navigationController.navigationBar.hidden = NO;
    if (!self.rdv_tabBarController.tabBarHidden) {
        [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
    }
}

-(void)viewWillDisappear:(BOOL)animated {
    if (self.rdv_tabBarController.tabBarHidden) {
        [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
    }
}

#pragma mark - View init
- (void)p_initNavgationBar {
    self.title = @"我的收入";
    self.view.backgroundColor = [UIColor whiteColor];
}

- (void)p_initCollectionView {
    UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc]init];
    self.mainCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) collectionViewLayout:flowLayout];
    self.mainCollectionView.delegate = self;
    self.mainCollectionView.dataSource = self;
    //设置contentInset属性（上左下右的值）
    self.mainCollectionView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
    self.mainCollectionView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.mainCollectionView];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 2;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            static NSString *ID = @"MineChargeWeekCellIdentifer";
            BCMineChargeWeekCollectionViewCell *cell = [BCMineChargeWeekCollectionViewCell cellWithCollectionView:collectionView];
            cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
            cell.weekBlock = ^(NSDate *weekStart, NSDate *weekEnd) {
                NSLog(@"%@-%@",[BCDateTool dateStringFromDate:weekStart],
                               [BCDateTool dateStringFromDate:weekEnd]);
            };
            return cell;
        }
        else if (indexPath.row == 1) {
            static NSString *ID = @"MineChargeMoneyCellIdentifer";
            BCMineChargeMoneyCollectionViewCell *cell = [BCMineChargeMoneyCollectionViewCell cellWithCollectionView:collectionView];
            cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
            return cell;
        }
        else {
            static NSString *ID = @"MineChargeInfoCellIdentifer";
            BCMineChargeInfoCollectionViewCell *cell = [BCMineChargeInfoCollectionViewCell cellWithCollectionView:collectionView];
            cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
            if (indexPath.row == 2) {
                cell.infoTitleLable.text = @"销售收入";
                cell.infoPriceLable.text = @"+1800.00元";
            }
            else if (indexPath.row == 3) {
                cell.infoTitleLable.text = @"发票";
                cell.infoPriceLable.text = @"+18.00元";
            }
            else {
                cell.infoTitleLable.text = @"平台费";
                cell.infoPriceLable.text = @"+180.00元";
            }
            return cell;
        }
    }
    else {
        static NSString *ID = @"MineLogoCell";
        BCLogoCollectionViewCell *cell = [BCLogoCollectionViewCell cellWithCollectionView:collectionView];
        cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
        if (SCREEN_WIDTH<=320.f) {
            cell.logoImageView.hidden = YES;
        }
        else {
            cell.logoImageView.hidden = NO;
        }
        return cell;
    }
}

-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section

{
    UIEdgeInsets top = {0,0,0,0};
    return top;
}

//定义每个UICollectionViewCell 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return CGSizeMake(self.view.frame.size.width, 65.f);
        }
        else if (indexPath.row == 1) {
            return CGSizeMake(self.view.frame.size.width, 172.f);
        }
        else {
            return CGSizeMake(self.view.frame.size.width, 60.f);
        }
    }
    else {
        CGFloat height = self.view.frame.size.height-65.f-172.f-(60.f*3);
        if (height<0) {
            height = 0;
        }
        return CGSizeMake(self.view.frame.size.width, height);
    }
}

//每个item之间的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 0;
}

//每个section中不同的行之间的行间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    
    return 0.f;
}

//collectionview点击
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        //        BCFindPassViewController *nextViewController = [[BCFindPassViewController alloc] init];
        //        [self.navigationController pushViewController:nextViewController animated:YES];
    }
}

@end
